import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'property_management.settings')
import django
django.setup()
from django.db import connection

with connection.cursor() as cursor:
    # 获取所有表名
    cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
    print('数据库表:')
    tables = cursor.fetchall()
    for table in tables:
        print(table[0])
    
    # 查看社区表结构
    print('\n查看社区表结构:')
    cursor.execute("PRAGMA table_info(community_community);")
    columns = cursor.fetchall()
    for col in columns:
        print(f"字段名: {col[1]}, 类型: {col[2]}, 非空: {col[3]}, 默认值: {col[4]}")
    
    # 查看一些示例数据
    print('\n社区表示例数据:')
    try:
        cursor.execute("SELECT id, name, total_households FROM community_community LIMIT 5;")
        data = cursor.fetchall()
        for row in data:
            print(row)
    except Exception as e:
        print(f"查询数据失败: {e}")